let vm = new Vue({
    el: '.main-content',
    data: function () {
        return {
            pageInfo: {},
            examine: {},
            name: "全部",
            condition: {
                type: '',
            },
            setting: {
                data: {
                    simpleData: {
                        enable: true,
                        idKey: "id",
                        pIdKey: "parentId"
                    },

                }, callback: {
                    onClick: this.onClick
                },

                view: {
                    fontCss: this.fontCss
                }
            },
            nodes: []
        }
    },
    methods: {
        selectPage: function (pageNum = 1, pageSize = 15) {

            axios({
                url: `mapper/examine/selectPage/${pageNum}/${pageSize}`,
                params: this.condition
            }).then(response => {
                this.pageInfo = response.data.obj;
            }).catch(error => {
                console.log(error.message)
            })
        },
        selectAll: function () {
            this.condition = {
                type: ''
            };
            this.selectPage()
        },


        initTree: function () {
            //初始化nodes数据
            axios({
                url: "mapper/office/selectAll"
            }).then(response => {
                this.nodes = response.data.obj;
                this.nodes[this.nodes.length] = {"id": 0, "name": "全部"};
                $.fn.zTree.init($("#pullDownTreeone"), this.setting, this.nodes);
            }).catch(error => {
                layer.msg(error.message)
            })

        },
        onClick: function (event, treeld, treeNode) {
            this.name = treeNode.name;
            if(treeNode.id===0){
                //全部
                this.condition.oid=null;
            }else{
                //绑定查询条件
                this.condition.oid=treeNode.id;
            }

            //删除open
            $(".btn-group").removeClass("open");

        },

        search: function () {
            // 1.获取树对象
            // 2.调用getNodesByParamFuzzy(属性名,属性值,父节点id)模糊匹配节点
            let zTreeObj = $.fn.zTree.getZTreeObj("pullDownTreeone");
            let NodesByParamFuzzy = zTreeObj.getNodesByParamFuzzy("name", this.name, null);

            let array = zTreeObj.transformToArray(zTreeObj.getNodes());
            for (let i in array) {
                //设置高亮属性
                array[i].hightLight = false;
                //更新树对象上的节点信息，会自动触发显示回调
                zTreeObj.updateNode(array[i])
            }

            for (let i in NodesByParamFuzzy) {
                //设置高亮属性
                NodesByParamFuzzy[i].hightLight = true;
                //更新树对象上的节点信息，会自动触发显示回调
                zTreeObj.updateNode(NodesByParamFuzzy[i])
            }

        },
        fontCss: function (treeId, treeNode) {
            // 根据高亮标记设置高亮红色
            return treeNode.hightLight ? {"color": "red"} : {"color": "black"}

        }

    },
    created: function () {
        this.selectPage();
    },
    mounted: function () {
        this.initTree();
    }

});